<?php

use yii\helpers\Url;

/* @var $this yii\web\View */
/* @var $model app\models\Patient */
/* @var $form yii\widgets\ActiveForm */
?>

<style type="text/css">
    #search_form_layer div.layui-form-item {
        margin-bottom: 0;
    }

    #search_form_layer div.layui-form-select dl {
        top: auto;
    }
</style>

<div id="search_form" style="display: none;">
    <form lay-filter="search_form_id" class="layui-form layui-form-pane" style="width:880px;margin:20px;" method="post">
        <input name="_csrf" type="hidden" id="_csrf" value="<?= Yii::$app->request->csrfToken ?>">
        <div class="layui-fluid layui-col-space30">
            <div class="layui-col-lg6" style="margin-left: -15px;">
                <div class="layui-form-item">
                    <label class="layui-form-label">姓名</label>
                    <div class="layui-input-block">
                        <input type="text" id="patient_name" name="search[name]" value="<?= $search['name'] ?>" placeholder="患者姓名" autocomplete="off" class="layui-input" />
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">电话</label>
                    <div class="layui-input-block">
                        <input type="number" id="patient_telphone" name="search[telphone]" value="<?= $search['telphone'] ?>" placeholder="患者电话" autocomplete="off" class="layui-input" />
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">性别</label>
                    <div class="layui-input-block">
                        <input type="radio" name="search[sex]" value="男" title="男" <?= $search['sex'] == '男' ? 'checked' : '' ?> />
                        <input type="radio" name="search[sex]" value="女" title="女" <?= $search['sex'] == '女' ? 'checked' : '' ?> />
                    </div>
                </div>

                <?php if ($this->context->module->requestedRoute != 'patient/record') { ?>
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否现场</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="search[istoday]" lay-skin="switch" lay-text="是|否" value="是" <?= $search['istoday'] == '是' ? 'checked' : '' ?> />
                        </div>
                    </div>
                <?php } ?>

                <div class="layui-form-item">
                    <label class="layui-form-label">永久身份</label>
                    <div class="layui-input-block">
                        <input type="text" name="search[forever_id]" value="<?= $search['forever_id'] ?>" placeholder="患者在商务通中的永久身份" autocomplete="off" class="layui-input" />
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">录入时间</label>
                    <div class="layui-input-block">
                        <input id="create_date_time" type="datetime" value="<?= $search['createtime'] ?>" name="search[createtime]" placeholder="录入时间" autocomplete="off" class="layui-input" />
                    </div>
                </div>

                <?php if ($this->context->module->requestedRoute != 'patient/indexrecord') { ?>
                    <div class="layui-form-item">
                        <label class="layui-form-label">预约时间</label>
                        <div class="layui-input-block">
                            <input id="order_date_time" type="datetime" value="<?= $search['order_time'] ?>" name="search[order_time]" placeholder="患者预约时间" autocomplete="off" class="layui-input" />
                        </div>
                    </div>

                    <?php if ($this->context->module->requestedRoute == 'patient/index') { ?>
                        <div class="layui-form-item">
                            <label class="layui-form-label">到诊时间</label>
                            <div class="layui-input-block">
                                <input id="arrive_date_time" type="datetime" value="<?= $search['arrive_time'] ?>" name="search[arrive_time]" placeholder="患者到诊时间" autocomplete="off" class="layui-input" />
                            </div>
                        </div>
                    <?php } ?>
                <?php } ?>

                <div class="layui-form-item input_border">
                    <label class="layui-form-label">预约疾病</label>
                    <div class="layui-input-block">
                        <select id="search_disease_ids" name="search[disease_ids]" lay-search>
                            <option value=""></option>
                            <?php foreach ($disease_array as $id => $name) { ?>
                                <option value="<?= $id ?>"><?= $name ?></option>
                            <?php } ?>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item input_border">
                    <label class="layui-form-label">来源渠道</label>
                    <div class="layui-input-block">
                        <select id="search_comeway_id" name="search[comeway_id]" lay-search>
                            <option value=""></option>
                            <?php foreach ($comeway_array as $d) { ?>
                                <option value="<?= $d['id'] ?>"><?= $d['name'] ?></option>
                            <?php } ?>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item input_border">
                    <label class="layui-form-label" lay-search>咨询方式</label>
                    <div class="layui-input-block">
                        <select id="search_communication_id" name="search[communication_id]">
                            <option value=""></option>
                            <?php foreach ($communication_array as $d) { ?>
                                <option value="<?= $d['id'] ?>"><?= $d['name'] ?></option>
                            <?php } ?>
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-col-lg6">

                <div class="layui-form-item <?= null != $user_array && count($user_array) > 1 ? '' : 'disabled' ?>">
                    <label class="layui-form-label">咨询人员</label>
                    <div class="layui-input-block">
                        <?php if (null != $user_array && count($user_array) > 1) { ?>
                            <select id="search_user_id" name="search[user_id]">
                                <option value=""></option>
                                <?php foreach ($user_array as $d) { ?>
                                    <option value="<?= $d['id'] ?>" <?= $d['checked'] ? 'selected="selected"' : '' ?>><?= $d['name'] ?></option>
                                <?php } ?>
                            </select>
                        <?php } else { ?>
                            <input type="text" disabled value="<?= Yii::$app->user->identity->showname ?>" autocomplete="off" class="layui-input" />
                        <?php }  ?>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">咨询班次</label>
                    <div class="layui-input-block">
                        <?php foreach ($workgroup_array as $d) { ?>
                            <input type="radio" name="search[workgroup]" value="<?= $d['id'] ?>" title="<?= $d['name'] ?>" <?= $d['checked'] ? 'checked="checked"' : '' ?> />
                        <?php } ?>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">年龄</label>
                    <div class="layui-input-block">
                        <input type="number" name="search[age]" value="<?= $search['age'] ?>" placeholder="患者年龄" autocomplete="off" class="layui-input" />
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">预约号</label>
                    <div class="layui-input-block">
                        <input type="text" name="search[order_number]" value="<?= $search['order_number'] ?>" placeholder="预约号" autocomplete="off" class="layui-input" />
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">微信</label>
                    <div class="layui-input-block">
                        <input type="text" name="search[wechat]" value="<?= $search['wechat'] ?>" placeholder="患者微信" autocomplete="off" class="layui-input" />
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">QQ</label>
                    <div class="layui-input-block">
                        <input type="text" name="search[qq]" value="<?= $search['qq'] ?>" placeholder="患者QQ" autocomplete="off" class="layui-input" />
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">搜关键词</label>
                    <div class="layui-input-block">
                        <input type="text" name="search[keyword]" value="<?= $search['keyword'] ?>" placeholder="患者搜索的关键词" autocomplete="off" class="layui-input" />
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">病情备注</label>
                    <div class="layui-input-block">
                        <input type="text" name="search[condition_log]" value="<?= $search['condition_log'] ?>" placeholder="患者的病情备注" autocomplete="off" class="layui-input" />
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">聊天记录</label>
                    <div class="layui-input-block">
                        <input type="text" name="search[talk_log]" value="<?= $search['talk_log'] ?>" placeholder="患者的聊天记录" autocomplete="off" class="layui-input" />
                    </div>
                </div>

                <?php if ($this->context->module->requestedRoute != 'patient/record') { ?>
                    <div class="layui-form-item input_border">
                        <label class="layui-form-label">接诊医生</label>
                        <div class="layui-input-block">
                            <select id="search_operate_doctor_id" name="search[operate_doctor_id]" lay-search>
                                <option value=""></option>
                                <?php foreach ($doctor_array as $d) { ?>
                                    <option value="<?= $d['id'] ?>"><?= $d['name'] ?></option>
                                <?php } ?>
                            </select>
                        </div>
                    </div>
                <?php } ?>

                <div class="layui-form-item input_border">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <select id="search_status" name="search[status]">
                            <option value=""></option>
                            <?php foreach ($status_array as $d) { ?>
                                <option value="<?= $d ?>"><?= $d ?></option>
                            <?php } ?>
                        </select>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-form-item button">
            <button class="layui-btn" lay-submit lay-filter="formBeforeSubmit" style="width: 100%;">
                立 即 搜 索
            </button>
        </div>
    </form>
</div>

<script>
    window.yyh_search_html = document.getElementById('search_form');

    function init_search_form() {
        <?php
        if (null != $search && count($search) > 0) {
            foreach ($search as $key => $v) {
                if (in_array($key, ['user_id', 'communication_id', 'operate_doctor_id', 'comeway_id', 'status', 'disease_ids']) && !empty($v)) {
                    echo "$('#search_" . $key . "').find('option[value=" . $v . "]').attr('selected',true);";
                }
            }
        }
        ?>
    }
    window.setTimeout("init_search_form()", 500);

    function show_search_form() {
        $('#search_form_layer').remove();
        layui.layer.open({
            id: 'search_form_layer',
            title: '患者搜索查询器',
            area: ['930px', 'auto'],
            shadeClose: true,
            type: 1,
            content: window.yyh_search_html.innerHTML, //这里content是一个普通的String
            success: function(layero, index) {
                layui.form.render();
                layui.laydate.render({
                    min: '2018-01-01',
                    elem: '#order_date_time, #arrive_date_time, #create_date_time',
                    range: true
                });
            }
        })
    }
</script>